package com.hotel.homehotel.before.controller;

import com.hotel.homehotel.before.entiy.Comment;
import com.hotel.homehotel.before.entiy.Reply;
import com.hotel.homehotel.before.entiy.Room;
import com.hotel.homehotel.before.service.CommentService;
import com.hotel.homehotel.before.service.impl.CommentServiceImpl;
import com.hotel.homehotel.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags="评论管理" ,value="评论管理")
@RequestMapping("/comment")
@CrossOrigin
public class CommentController {
    @Autowired
    CommentService commentService;


    @ApiOperation(value = "根据房间id查看该房间下的所有评论和二级评论(后台管理查评论就传-1)")
    @GetMapping("/selectByRoomId/{roomId}")
    public R selectByRoomId(@ApiParam(name = "roomId", value = "房间id", required = true)
                               @PathVariable     String roomId){
         System.out.println( commentService.selectByRoomId(roomId));
        return  R.define(true,200,"获取成功").data("comment",commentService.selectByRoomId(roomId));
    }

    @ApiOperation(value = "添加评论")
    @PostMapping("/insertComment")
    public R insertComment(@RequestBody Comment comment){
          System.out.println("1111"+comment.getContent());
        return  R.define(true,200,"添加成功").data("comment",commentService.insertComment(comment));
    }

    @ApiOperation(value = "测试")
    @PostMapping("/insertComment111")
    public R insertComment111(){
        System.out.println("1111");
        return  R.define(true,200,"添加成功");
    }
    @ApiOperation(value = "添加二级回复")
    @PostMapping("/insertReply")
    public R insertReply(@RequestBody Reply reply){

        return  R.define(true,200,"添加成功").data("comment",commentService.insertReply(reply));
    }

    @ApiOperation(value = "删除评论（包括该评论下的二级所有回复）")
    @GetMapping("/deleteComment/{id}")
    public R deleteComment(@ApiParam(name = "id", value = "评论id", required = true)
                               @PathVariable     String id){
             commentService.deleteComment(id);
        return  R.define(true,200,"删除成功");
    }

    @ApiOperation(value = "删除二级回复")
    @GetMapping("/deleteReply/{id}")
    public R deleteReply(@ApiParam(name = "id", value = "回复id", required = true)
                             @PathVariable     String id){
         commentService.deleteReply(id);
        return  R.define(true,200,"删除成功");
    }




}
